--[[
    宠物交易行交易列表
--]]

require "Common/define"
require "Logic/Config"
require "Net/send_Msg"
require "Common/functions"
require "Logic/BrokerManager"
require "Logic/BrokerUtils"


UIPetShop = UIPetShop or {}
HelperFunc.SetUIEnv(UIPetShop)
local this = UIPetShop

this.hasInit = false
this.clickIdex = 1
this.refreshTimeNum = 0
this.timeRefresh = nil

--- @type boolean
local mIsPriceFilter = false -- 是否选择价格筛选

--- @type number
local mPriceSellMin = nil   -- 出售最低价格
--- @type number
local mPriceSellMax = nil   -- 出售最高价格
--- @type number
local mPriceEvolutioMin = nil   -- 进化最低价格
--- @type number
local mPriceEvolutioMax = nil   -- 进化最高价格

--- @type number[]
local mQuickPriceRange1_1 = nil   -- 快速选择价格区间1（出售）
--- @type number[]
local mQuickPriceRange1_2 = nil   -- 快速选择价格区间1（进化）
--- @type number[]
local mQuickPriceRange2   = nil   -- 快速选择价格区间2
--- @type number[]
local mQuickPriceRange3   = nil   -- 快速选择价格区间3
--- @type number[]
local mQuickPriceRange4_1 = nil   -- 快速选择价格区间4（出售）
--- @type number[]
local mQuickPriceRange4_2 = nil   -- 快速选择价格区间4（进化）

function this.Init()
    local name, packageName = getUIName(PanelNames.UIPetShop)
    panelMgr:ShowUI(name, packageName, this.onCreate, Config.useLocalUI)
end
function this.onCreate(in_root)
    if not this.hasInit then
        this.hasInit = true
        this.Btn_Back = in_root:GetChild("Btn_Back")
        this.Btn_Back.onClick:Add(this.onClickClose)
        this.Comp_PetCoin = in_root:GetChild("Comp_PetCoin")
        this.Btn_PetCoinAdd = this.Comp_PetCoin:GetChild("add")
        this.Btn_PetCoinAdd.onClick:Add(this.onClickPetCoinAdd)
        this.Comp_Diamond = in_root:GetChild("Comp_Diamond")
        this.Btn_DiamondAdd = this.Comp_Diamond:GetChild("add")
        this.Btn_DiamondAdd.onClick:Add(this.onClickDiamondAdd)
        this.Img_PetMainBg = in_root:GetChild("Img_PetMainBg")

        this.Ctrl_ShopType = in_root:GetController("ShopType")
        this.Tab_PetBroker = in_root:GetChild("Tab_PetBroker")
        this.Tab_PetBroker.onClick:Add(this.onClickTabPetBroker)
        this.Tab_OrderHistory = in_root:GetChild("Tab_OrderHistory")
        this.Tab_OrderHistory.onClick:Add(this.onClickTabOrderHistory)
        this.Tab_MyAdded = in_root:GetChild("Tab_MyAdded")
        this.Tab_MyAdded.onClick:Add(this.onClickTabMyAdded)
        this.Btn_Tip = in_root:GetChild("help")
        this.Btn_Tip.onClick:Add(this.HelpTip)

        --交易行宠物列表主页面
        this.initPetShopMain(in_root:GetChild("Page_PetShopMain"))
        
        --我的寄售订单页面
        this.initPetShowMyConsignment(in_root:GetChild("Page_PetShopMyConsignment"))

        --- 飞飞价格筛选弹窗控制器
        --- @type GController
        this.ctrlPriceFilter = in_root:GetController("Screening")
        this.initPriceFilterView(in_root:GetChild("UIPetShopScreening"))
        
        --上架我的宠物页面
        this.initPetShopMyAdded(in_root:GetChild("Page_PetShopMyAdded"))
        ListenEvent(Config.EventType.PETSHOP_RefreshBrokerGoodsList, this.eventRefreshBrokerPetInfoList)
        ListenEvent(Config.EventType.PETSHOP_RefreshBrokerEvolutionList, this.eventRefreshBrokerEvolutionList)
        ListenEvent(Config.EventType.PETSHOP_RefreshMyConsignmentList, this.eventRefreshMyConsignmentList)
        ListenEvent(Config.EventType.Fresh_Currency, this.eventRefreshDiamondNum)
        ListenEvent(Config.EventType.SelectPet, this.eventSelectPet)
        ListenEvent(Config.EventType.RenovePetChild,this.Updatalist)
        this.clickIdex = 1
    end
    this.eventRefreshDiamondNum()
    this.timerIdList = {}
    this.brokerMainPetModelTable = {}
    this.myConsignmentPetModelTable = {}
    this.addedPetModelTable = {}
    this.canAddedPetInfoList = {}           --可以上架的宠物列表
    this.onClickTabPetBroker()
end

function this.OnDisable()
    this.Btn_Back.onClick:Clear()
    this.Tab_PetBroker.onClick:Clear()
    this.Tab_OrderHistory.onClick:Clear()
    this.Tab_MyAdded.onClick:Clear()
    this.Btn_Tip.onClick:Clear()

    this.hidePetShopMain()
    this.hidePetShowMyConsignment()
    this.hidePetShopMyAdded()
    this.removeTimerId()
    this.destroyPriceFilterView()

    this.Btn_PetCoinAdd.onClick:Clear()
    this.Btn_DiamondAdd.onClick:Clear()
    CloseEvent(Config.EventType.PETSHOP_RefreshBrokerGoodsList, this.eventRefreshBrokerPetInfoList)
    CloseEvent(Config.EventType.PETSHOP_RefreshBrokerEvolutionList, this.eventRefreshBrokerEvolutionList)
    CloseEvent(Config.EventType.PETSHOP_RefreshMyConsignmentList, this.eventRefreshMyConsignmentList)
    CloseEvent(Config.EventType.Fresh_Currency, this.eventRefreshDiamondNum)
    CloseEvent(Config.EventType.SelectPet, this.eventSelectPet)
    CloseEvent(Config.EventType.RenovePetChild,this.Updatalist)
    
    this.hasInit = false
end

function this.HelpTip()
    logicMgr.UIShowManager.ShowCommonTips("HelpTitle44", "HelpDes44", "FunctionStory1150")
end

function this.onClickClose()
    this.OnDisable()
    closeUI(PanelNames.UIPetShop)
end

function this.removeTimerId()
    for _, timerId in pairs(this.timerIdList) do
        if timerId then
            utimer.remove(timerId)
            timerId = nil
        end
    end
    this.timerIdList = {}
end

function this.eventRefreshPetCoinNum()
    this.Comp_PetCoin.title = BrokerManager.GetCurrentPetCoin()
end
function this.eventRefreshDiamondNum()
    this.Comp_Diamond.title = ItemManager.getCurrencyCountByModelId(CurrencyEnum.GOLD)
    this.eventRefreshPetCoinNum()
end
function this.onClickPetCoinAdd()
    if logicMgr.FuncOpenManager.isOpen(Config.FuncOpenType.Cost, true, this.Btn_PetCoinAdd) then
        logicMgr.CostManager.gotoCostById(10207);
    end
end
function this.onClickDiamondAdd()
    if logicMgr.FuncOpenManager.isOpen(Config.FuncOpenType.Cost, true, this.Btn_DiamondAdd) then
        logicMgr.CostManager.gotoCostById(10207);
    end
end

function this.Updatalist()
    if BrokerManager.BrokerPetType == BrokerUtils.BrokerPetType.Buy then
        this.List_BrokerMainPetGoods:RemoveChild(BrokerManager.clickObj[BrokerUtils.BrokerPetType.Buy][1])
    else
        if BrokerManager.clickObj[BrokerUtils.BrokerPetType.Buy] and BrokerManager.clickObj[BrokerUtils.BrokerPetType.Buy][1] then
            this.List_MyConsignment:RemoveChild(BrokerManager.clickObj[BrokerUtils.BrokerPetType.Buy][1])
        end
    end
    if BrokerManager.clickObj[BrokerManager.BrokerPetType] and BrokerManager.clickObj[BrokerManager.BrokerPetType][2] then
        BrokerManager.RemovePetByTypeAndIndex(BrokerManager.BrokerPetType,BrokerManager.clickObj[BrokerManager.BrokerPetType][2])
    end
end
--交易行第一页签 寄售主界面-----------------------------------------------------------------------
function this.initPetShopMain(in_brokerMainRoot)
    this.petGoodsCtrl = in_brokerMainRoot:GetController("NotPet")
    this.List_BrokerMainPetGoods = in_brokerMainRoot:GetChild("List_BrokerMainPetGoods"):GetChild("List_Pet")
    this.List_BrokerMainPetGoods.itemRenderer = this.itemRendererMainPetGoods
    this.List_BrokerMainPetGoods.onClickItem:Add(this.onClickItemMainPetGoods)
    this.List_BrokerMainPetGoods.scrollPane.onScrollEnd:Add(this.onScrollEndMainPetGoods)
    this.btnCtrl = in_brokerMainRoot:GetController("c1")
    this.btnCtrl.selectedIndex = 0
    this.Btn_BrokerBuy = in_brokerMainRoot:GetChild("Btn_BrokerBuy")
    this.Btn_BrokerBuy.title = getLanguage("PETSHOP_TitleBuyList")
    this.Btn_BrokerBuy.onClick:Add(this.onClickBrokerBuy)
    this.Btn_BrokerEvolution = in_brokerMainRoot:GetChild("Btn_BrokerEvolution")
    this.Btn_BrokerEvolution.title = getLanguage("PETSHOP_TitleEvolutionList")
    this.Btn_BrokerEvolution.onClick:Add(this.onClickBrokerEvolution)

    --- 价格筛选按钮
    this.Ctrl_BtnScreening = in_brokerMainRoot:GetController("BtnShow")
    this.Btn_Screening = in_brokerMainRoot:GetChild("Btn_Screening")
    this.Btn_Screening.onClick:Add(this.onClickSceening)

    --- 重置价格筛选按钮
    this.Btn_Reset = in_brokerMainRoot:GetChild("reset")
    this.Btn_Reset.onClick:Add(this.onClickReset)

    --- 价格筛选title
    this.txtPriceRangeTitle = in_brokerMainRoot:GetChild("Tittle")
    this.refreshPriceRangeTitle(BrokerUtils.BrokerPetType.Buy)
end
function this.hidePetShopMain()
    this.List_BrokerMainPetGoods.onClickItem:Remove(this.onClickItemMainPetGoods)
    this.List_BrokerMainPetGoods.scrollPane.onScrollEnd:Remove(this.onScrollEndMainPetGoods)
    this.Btn_BrokerBuy.onClick:Clear()
    this.Btn_BrokerEvolution.onClick:Clear()
    this.Btn_Screening.onClick:Clear()
    this.Btn_Reset.onClick:Clear()

    PetManager.RemovePetModelTable(this.brokerMainPetModelTable)
    BrokerManager.BrokerPetType = BrokerUtils.BrokerPetType.Buy
    BrokerManager.BrokerSellPetList = {}
    BrokerManager.BrokerSellPetPage = 1
    BrokerManager.HasBrokerSellNextPage = false
    BrokerManager.BrokerEvolutionPetList = {}
    BrokerManager.BrokerEvolutionPetPage = 1
    BrokerManager.HasBrokerEvolutionNextPage = false
end
function this.onClickTabPetBroker()
    this.btnCtrl.selectedIndex = 0
    if this.clickIdex == 1 then
        return
    end
    BrokerManager.BrokerPetType = BrokerUtils.BrokerPetType.Buy
    this.List_MyConsignment.numItems = 0
    if this.onClickRefresh() then
        BrokerHandler.ReqBrokerGoodsList(BrokerUtils.BrokerPetType.Buy,1)
    end
    this.clickIdex = 1
end
function this.eventRefreshBrokerPetInfoList()
    this.Img_PetMainBg:GetChild("title").text = getLanguage("PETSHOP_BannerTips1")

    -- 价格筛选
    if mIsPriceFilter then
        this.refreshPriceRangeList()
        return
    end

    --this.Ctrl_ShopType:SetSelectedIndex(0)
    this.removeTimerId()
    if BrokerManager.BrokerPetType == BrokerUtils.BrokerPetType.Buy then
        if #BrokerManager.BrokerSellPetList> 0 then
            PetManager.RemovePetModelTable(this.brokerMainPetModelTable)
            this.brokerMainPetModelTable = {}

            this.petGoodsCtrl.selectedIndex = 0
            this.List_BrokerMainPetGoods.numItems = table.getn(BrokerManager.BrokerSellPetList)
            --HelperFunc.ListTranstionPlay(this.List_BrokerMainPetGoods)
        else
            this.petGoodsCtrl.selectedIndex = 1
        end
    elseif BrokerManager.BrokerPetType == BrokerUtils.BrokerPetType.Evolution then
        if #BrokerManager.BrokerEvolutionPetList >0 then
            PetManager.RemovePetModelTable(this.brokerMainPetModelTable)
            this.brokerMainPetModelTable = {}

            this.petGoodsCtrl.selectedIndex = 0
            this.List_BrokerMainPetGoods.numItems = table.getn(BrokerManager.BrokerEvolutionPetList)
            --HelperFunc.ListTranstionPlay(this.List_BrokerMainPetGoods)
        else
            this.petGoodsCtrl.selectedIndex = 1
        end
    end
end
function this.eventRefreshBrokerEvolutionList()
    -- 价格筛选
    if mIsPriceFilter then
        this.refreshPriceRangeList()
        return
    end

    --this.Ctrl_ShopType:SetSelectedIndex(0)
    this.removeTimerId()
    
    if BrokerManager.BrokerPetType == BrokerUtils.BrokerPetType.Evolution then
        if #BrokerManager.BrokerEvolutionPetList >0 then
            PetManager.RemovePetModelTable(this.brokerMainPetModelTable)
            this.brokerMainPetModelTable = {}

            this.petGoodsCtrl.selectedIndex = 0
            this.List_BrokerMainPetGoods.numItems = table.getn(BrokerManager.BrokerEvolutionPetList)
        else
            this.petGoodsCtrl.selectedIndex = 1
        end
    end
end

function this.itemRendererMainPetGoods(in_index,in_itemRoot)
    local _petListIndex = tonumber(in_index)+1

    -- local _petInfo = BrokerManager.GetPetInfoByIndex(_petListIndex,BrokerManager.BrokerPetType)
    local _petInfo = this.getPetInfo(_petListIndex, BrokerManager.BrokerPetType)
    if nil == _petInfo then
        return
    end

    in_itemRoot:GetChild("Txt_PetName").text = _petInfo.petName
    local _btnPetIcon = in_itemRoot:GetChild("Btn_PetIcon")
    _btnPetIcon.onClick:Clear()
    _btnPetIcon.onClick:Add(function ()
        BrokerManager.clickObj[BrokerManager.BrokerPetType] = {in_itemRoot,_petListIndex}
        BrokerManager.DetailSelectedPetId = _petInfo.petId
        showUI(PanelNames.UIPetShopPetDetail)
    end)

    local _btnConfirm = in_itemRoot:GetChild("Btn_Confirm")
    local _confirmStr = ""
    local _price = 0
    if BrokerManager.BrokerPetType == BrokerUtils.BrokerPetType.Buy then
        _confirmStr = getLanguage("PETSHOP_TitleBuy")
        _price = _petInfo.sellPrice
    elseif BrokerManager.BrokerPetType == BrokerUtils.BrokerPetType.Evolution then
        _confirmStr = getLanguage("PETSHOP_TitleEvolution")
        _price = _petInfo.evolutionPrice
    end
    _btnConfirm:GetChild("title").text = _confirmStr
    _btnConfirm.onClick:Clear()
    _btnConfirm.onClick:Add(function ()
        BrokerManager.clickObj[BrokerManager.BrokerPetType] = {in_itemRoot,_petListIndex}
        BrokerManager.DetailSelectedPetId = _petInfo.petId
        showUI(PanelNames.UIPetShopPetDetail)
    end)
    in_itemRoot:GetChild("Txt_Price").text = _price
    
    --倒计时
    local _txtCountDown = in_itemRoot:GetChild("Txt_CountDown")
    local _countDown = _petInfo.registerTime + BrokerManager.PetConsignmentDuration - HelperFunc.GetServerTime()
    _countDown = _countDown < 0 and 0 or _countDown
    _txtCountDown.text = TimeFormatToHHMMSS(_countDown)
    if this.timerIdList[_petListIndex] then
        utimer.remove(this.timerIdList[_petListIndex])
        this.timerIdList[_petListIndex] = nil
    end
    if _countDown > 0 then
        this.timerIdList[_petListIndex] = utimer.timeCall(function ()
            _countDown = _countDown - 1
            if _countDown < 0 then
                if this.timerIdList[_petListIndex] then
                    utimer.remove(this.timerIdList[_petListIndex])
                    this.timerIdList[_petListIndex] = nil
                end
                this.List_BrokerMainPetGoods:RemoveChild(in_itemRoot)
                if not mIsPriceFilter then
                    BrokerManager.RemovePetByTypeAndIndex(BrokerManager.BrokerPetType, _petListIndex)
                end
            else
                _txtCountDown.text = TimeFormatToHHMMSS(_countDown)
            end
        end,1000,_countDown)
    else
        this.List_BrokerMainPetGoods:RemoveChild(in_itemRoot)
        if not mIsPriceFilter then
            BrokerManager.RemovePetByTypeAndIndex(BrokerManager.BrokerPetType, _petListIndex)
        end
    end

    local _petFrame = in_itemRoot:GetChild("Btn_PetFrame")
    local _petMutationLevel = PetManager.GetMutationLevel(_petInfo.genes)
    _petFrame:GetController("level"):SetSelectedIndex(_petMutationLevel - 1)
    _petFrame:GetChild("frame").url = PetManager.GetMutationLevelFrameIcon(_petMutationLevel)

    --显示宠物模型
    -- PetManager.LoadItemPetModel(_petInfo,this.brokerMainPetModelTable,tostring(_petInfo.petId),_petFrame:GetChild("Model_Pet"))
    PetManager.LoadItemPetModel(_petInfo,this.brokerMainPetModelTable,_petListIndex,_petFrame:GetChild("Model_Pet"))
end

function this.onClickItemMainPetGoods(in_context)
    -- local _index = this.List_BrokerMainPetGoods:GetChildIndex(in_context.data)
    -- -- local _petInfo = BrokerManager.GetPetInfoByIndex(_index + 1,BrokerManager.BrokerPetType)
    -- local _petInfo = this.getPetInfo(_index + 1, BrokerManager.BrokerPetType)
    -- BrokerManager.DetailSelectedPetId = _petInfo.petId
end
function this.onScrollEndMainPetGoods()
    -- 价格筛选列表不会下拉刷新
    if mIsPriceFilter then
        return
    end

    local _currentMaxPage = 0
    local num
    if BrokerManager.BrokerPetType == BrokerUtils.BrokerPetType.Buy then
        num = #BrokerManager.BrokerSellPetList
        _currentMaxPage = math.ceil(num /10)
    elseif BrokerManager.BrokerPetType == BrokerUtils.BrokerPetType.Evolution then
        num = #BrokerManager.BrokerEvolutionPetList
        _currentMaxPage = math.ceil(num / 10)
    end
    if num ~= _currentMaxPage*10 then
        return
    end
    BrokerHandler.ReqBrokerGoodsList(BrokerManager.BrokerPetType,_currentMaxPage+1)
end

function this.onClickBrokerBuy()
    this.btnCtrl.selectedIndex = 0
    this.resetPriceFilter()
    this.refreshPriceRangeTitle(BrokerUtils.BrokerPetType.Buy)
    BrokerHandler.ReqBrokerGoodsList(BrokerUtils.BrokerPetType.Buy,1)
end
function this.onClickBrokerEvolution()
    this.btnCtrl.selectedIndex = 1
    this.resetPriceFilter()
    this.refreshPriceRangeTitle(BrokerUtils.BrokerPetType.Evolution)
    BrokerHandler.ReqBrokerGoodsList(BrokerUtils.BrokerPetType.Evolution,1)
end
function this.onClickSceening()
    local min, max = this.getPriceRange()
    this.refreshPriceInputText(min, max)
    this.refreshBtnPriceText()
    this.ctrlPriceFilter.selectedIndex = 1
end
function this.onClickReset()
    if not mIsPriceFilter then
        return
    end
    this.resetPriceFilter()
    this.refreshPriceRangeTitle()
    BrokerHandler.ReqBrokerGoodsList(BrokerManager.BrokerPetType, 1)
end

--- 获取宠物信息
--- @private
--- @param index number 索引
--- @param type  number 列表类型
--- @return any 宠物信息
function this.getPetInfo(index, type)
    if mIsPriceFilter then
        return BrokerManager.GetPetInfoFromPriceRangeByIndex(index, type)
    end
    return BrokerManager.GetPetInfoByIndex(index, type)
end

--- 刷新价格筛选按钮状态
function this.refreshPriceFilterBtnState()
    this.Ctrl_BtnScreening.selectedIndex = mIsPriceFilter and 1 or 0
end

--- 刷新价格区间title
--- @private
--- @param type number 列表类型
function this.refreshPriceRangeTitle(type)
    if this.txtPriceRangeTitle == nil then
        return
    end

    type = type or BrokerManager.BrokerPetType
    local min, max = this.getPriceRange(type)
    min = min or this.getOriginPriceMin(type)
    max = max or this.getOriginPriceMax(type)
    if max > this.getOriginPriceMax(type) then
        this.txtPriceRangeTitle.text = string.format(getLanguage("PETSHOP_tips_008"), min)
    else
        this.txtPriceRangeTitle.text = string.format(getLanguage("PETSHOP_tips_007"), min, max)
    end
end

--- 根据价格筛选刷新宠物列表
--- @private
function this.refreshPriceRangeList()
    this.removeTimerId()

    local min, max = this.getPriceRange()
    BrokerManager.ParsePetPriceRangeList(BrokerManager.BrokerPetType, min, max)

    local cnt
    if BrokerManager.BrokerPetType == BrokerUtils.BrokerPetType.Buy then
        cnt = table.getn(BrokerManager.BrokerSellPetPriceRangeList)
    elseif BrokerManager.BrokerPetType == BrokerUtils.BrokerPetType.Evolution then
        cnt = table.getn(BrokerManager.BrokerEvolutionPetPriceRangeList)
    end

    if cnt > 0 then
        PetManager.RemovePetModelTable(this.brokerMainPetModelTable)
        this.brokerMainPetModelTable = {}
        this.petGoodsCtrl.selectedIndex = 0
        this.List_BrokerMainPetGoods.numItems = cnt
    else
        this.petGoodsCtrl.selectedIndex = 1
    end
end

--------------------------------------------------------------------------------------------

--交易行第二页签 我已经寄售的宠物列表界面---------------------------------------------------------------------------
function this.initPetShowMyConsignment(in_myConsignmentRoot)
        this.consignmentCtrl = in_myConsignmentRoot:GetController("NotPet")
        this.List_MyConsignment = in_myConsignmentRoot:GetChild("List_MyConsignment"):GetChild("List_Pet")
        this.List_MyConsignment.itemRenderer = this.itemRendererMyConsignment
        this.List_MyConsignment.onClickItem:Add(this.onClickItemMyConsignment)
        this.Txt_MyConsignmentCountLimit = in_myConsignmentRoot:GetChild("bannerText")
end
function this.hidePetShowMyConsignment()
    this.List_MyConsignment.onClickItem:Remove(this.onClickItemMyConsignment)

    PetManager.RemovePetModelTable(this.myConsignmentPetModelTable)
    BrokerManager.MyConsignmentList = {}
end

function this.onClickTabOrderHistory()
    if this.clickIdex == 2 then
        return
    end
    this.Img_PetMainBg:GetChild("title").text  = getLanguage("PETSHOP_BannerTips2")
    if BrokerManager.BrokerPetType ~= BrokerUtils.BrokerPetType.Myself then
        if this.onClickRefresh() then
            BrokerHandler.ReqBrokerGoodsList(BrokerUtils.BrokerPetType.Myself,1)
        end
    end
    this.Ctrl_ShopType:SetSelectedIndex(1)
    BrokerManager.BrokerPetType = BrokerUtils.BrokerPetType.Myself
    if #BrokerManager.MyConsignmentList >0 then
        this.consignmentCtrl.selectedIndex = 0
        this.List_MyConsignment.numItems = table.getn(BrokerManager.MyConsignmentList)
    else
        this.consignmentCtrl.selectedIndex = 1
    end
    this.Txt_MyConsignmentCountLimit.text = string.format(getLanguage("PETSHOP_MyConsignmentCountLimit"),
        table.getn(BrokerManager.MyConsignmentList),BrokerManager.PetConsignmentMaxCount)
    this.clickIdex = 2
end

function this.itemRendererMyConsignment(in_index,in_itemRoot)
    local _petListIndex = in_index + 1
    local _petInfo = BrokerManager.MyConsignmentList[_petListIndex]
    if nil == _petInfo then
        return
    end
    in_itemRoot:GetChild("Txt_PetName").text = _petInfo.petName
    in_itemRoot:GetController("Sell"):SetSelectedIndex(_petInfo.sellPrice == -1 and 0 or 1)
    in_itemRoot:GetController("Evolution"):SetSelectedIndex(_petInfo.evolutionPrice == -1 and 0 or 1)
    in_itemRoot:GetChild("Txt_SellNum").text = _petInfo.sellPrice == -1 and getLanguage("PETSHOP_NotAdded") or _petInfo.sellPrice
    in_itemRoot:GetChild("Txt_EvolutionNum").text = _petInfo.evolutionPrice == -1 and getLanguage("PETSHOP_NotAdded") or _petInfo.evolutionPrice
    local isTimme = in_itemRoot:GetController("IsTime")
    local btn_get = in_itemRoot:GetChild("get")
    btn_get.onClick:Clear()
    btn_get.onClick:Add(function()
        BrokerManager.isCanClick = nil
        if #PetManager.PetInfoList < PetManager.MaxPetCount then
            BrokerManager.isCanClick = nil
            BrokerHandler.ReqUnRegisterPet(_petInfo.goodsId)
            this.List_MyConsignment:RemoveChild(in_itemRoot)
            BrokerManager.RemovePetByTypeAndIndex(BrokerManager.BrokerPetType,_petListIndex)
            this.Txt_MyConsignmentCountLimit.text = string.format(getLanguage("PETSHOP_MyConsignmentCountLimit"),
                    table.getn(BrokerManager.MyConsignmentList),BrokerManager.PetConsignmentMaxCount)
        else
            UISysTips.AddMsg(getLanguage("PETSHOP_PetBagFull"))
            return
        end
    end)
    --倒计时
    local _txtCountDown = in_itemRoot:GetChild("Txt_CountDown")
    local _countDown = _petInfo.registerTime + BrokerManager.PetConsignmentDuration - HelperFunc.GetServerTime()
    _countDown = _countDown < 0 and 0 or _countDown
    _txtCountDown.text = TimeFormatToHHMMSS(_countDown)
    if this.timerIdList[_petListIndex] then
        utimer.remove(this.timerIdList[_petListIndex])
        this.timerIdList[_petListIndex] = nil
    end
    if _countDown > 0 then
        this.timerIdList[_petListIndex] = utimer.timeCall(function ()
            _countDown = _countDown - 1
            if _countDown < 0  then
                if this.timerIdList[_petListIndex] then
                    utimer.remove(this.timerIdList[_petListIndex])
                    this.timerIdList[_petListIndex] = nil
                end
                isTimme.selectedIndex = 1
            else
                isTimme.selectedIndex = 0
                _txtCountDown.text = TimeFormatToHHMMSS(_countDown)
            end
        end,1000,_countDown)
    else
        isTimme.selectedIndex = 1
    end
    in_itemRoot.onClick:Clear()
    in_itemRoot.onClick:Add(function ()
        if not BrokerManager.isCanClick then
            BrokerManager.isCanClick = true
            return
        end
        BrokerManager.clickObj[BrokerManager.BrokerPetType] = {in_itemRoot,_petListIndex}
        BrokerManager.DetailSelectedPetId = _petInfo.petId
        showUI(PanelNames.UIPetShopPetDetail)
    end)

    local _petFrame = in_itemRoot:GetChild("Btn_PetFrame")
    local _petMutationLevel = PetManager.GetMutationLevel(_petInfo.genes)
    _petFrame:GetController("level"):SetSelectedIndex(_petMutationLevel - 1)
    _petFrame:GetChild("frame").url = PetManager.GetMutationLevelFrameIcon(_petMutationLevel)
    --显示宠物模型
    PetManager.LoadItemPetModel(_petInfo,this.myConsignmentPetModelTable,_petListIndex,_petFrame:GetChild("Model_Pet"))
end
function this.onClickItemMyConsignment(in_context)
    local _index = this.List_MyConsignment:GetChildIndex(in_context.data)
    local _petInfo = BrokerManager.MyConsignmentList[_index+1]
    BrokerManager.DetailSelectedPetId = _petInfo.petId
end
function this.eventRefreshMyConsignmentList()
    this.clickIdex = 0
    PetManager.RemovePetModelTable(this.myConsignmentPetModelTable)
    this.List_MyConsignment.numItems = 0
    this.onClickTabOrderHistory() 
end

--------------------------------------------------------------------------------------------

--上架我的宠物界面---------------------------------------------------------------------------
function this.initPetShopMyAdded(in_myAddedRoot)
    this.Ctrl_PetAddedType = in_myAddedRoot:GetController("PetAddedType")

    this.Btn_MyAddedConfirm = in_myAddedRoot:GetChild("Btn_MyAddedConfirm")
    this.Btn_MyAddedConfirm.title = getLanguage("PETSHOP_AddedText")
    this.Btn_MyAddedConfirm.onClick:Add(this.onClickMyAddedConfirm)
    this.Btn_MyAddedChoosePet = in_myAddedRoot:GetChild("Btn_MyAddedChoosePet")
    this.Btn_MyAddedChoosePet.title = getLanguage("PETSHOP_AddedChoosePet")
    this.Btn_MyAddedChoosePet.onClick:Add(this.onClickMyAddedChoosePet)

    this.Txt_MyAddedDealNote = in_myAddedRoot:GetChild("Txt_MyAddedDealNote")
    this.Txt_MyAddedDealNote.text = string.format(getLanguage("PETSHOP_DealNote"),BrokerManager.PetAddedFee,"%")

    this.Model_MyAddedPet = in_myAddedRoot:GetChild("Model_MyAddedPet")
    this.Group_PetPartItem = {}
    for i = 1, PetManager.PetPart.Ornament do
        local _partIndex = i > 9 and i or "0" .. i
        local _partItem = in_myAddedRoot:GetChild("Btn_MyPetBodyShow" .. _partIndex)
        table.insert(this.Group_PetPartItem, _partItem)
    end
    this.Txt_MyAddedTitle = in_myAddedRoot:GetChild("Txt_MyAddedTitle")
    this.Txt_MyAddedTitle.text = getLanguage("PETSHOP_MyAddedTitle")
    this.Txt_MyAddedPetName = in_myAddedRoot:GetChild("Txt_MyAddedPetName")

    this.Btn_SellSelected = in_myAddedRoot:GetChild("Btn_SellSelected")
    this.Btn_SellSelected.onClick:Add(this.onClickSellSelected)
    this.Btn_EvolutionSelected = in_myAddedRoot:GetChild("Btn_EvolutionSelected")
    this.Btn_EvolutionSelected.onClick:Add(this.onClickEvolutionSelected)
    

    this.Input_SellPrice = in_myAddedRoot:GetChild("Input_SellPrice")
    this.Input_SellPrice.onChanged:Clear()
    this.Input_SellPrice.onChanged:Add(this.ClickBuyInput)
    this.Input_EvolutionPrice = in_myAddedRoot:GetChild("Input_EvolutionPrice")
    this.Input_EvolutionPrice.onChanged:Clear()
    this.Input_EvolutionPrice.onChanged:Add(this.ClickInput)

    this.Txt_SellPrice = in_myAddedRoot:GetChild("Txt_SellPrice")
    this.Txt_EvolutionPrice = in_myAddedRoot:GetChild("Txt_EvolutionPrice")

    this.Txt_MyAddedNoPet = in_myAddedRoot:GetChild("Txt_MyAddedNoPet")
    this.Txt_MyAddedNoPet.text = getLanguage("PETSHOP_PetAddedNoPet")

end

function this.ClickBuyInput()
   local putStr =  this.Input_SellPrice.text
    local bit = tonumber(string.sub(putStr,string.len(putStr) -1))
    if(not bit) or type(bit)~= "number" then
        UISysTips.AddMsg(getLanguage("PETSHOP_PriceNumber"))
        return
    end
end

function this.ClickInput()
    local putStr =  this.Input_EvolutionPrice.text
    local bit = tonumber(string.sub(putStr,string.len(putStr) -1))
    if(not bit) or type(bit)~= "number" then
        UISysTips.AddMsg(getLanguage("PETSHOP_PriceNumber"))
        return
    end
end

function this.hidePetShopMyAdded()
    this.Btn_MyAddedConfirm.onClick:Clear()
    this.Btn_MyAddedChoosePet.onClick:Clear()
    this.Btn_SellSelected.onClick:Clear()
    this.Btn_EvolutionSelected.onClick:Clear()

    this.removMyAddedPetModel()
    this.Group_PetPartItem = {}
    BrokerManager.BrokerAddedPetId = 0
    
    PetManager.RemovePetModelTable(this.addedPetModelTable)
end

function this.onClickTabMyAdded()
    if this.clickIdex == 3 then
        return
    end
    BrokerManager.BrokerPetType = 0
    this.Img_PetMainBg:GetChild("title").text  = getLanguage("PETSHOP_BannerTips3")
    if this.myAddedPetModelInfo == nil then
        this.myAddedPetModelInfo = {}
    end
    this.Ctrl_ShopType:SetSelectedIndex(2)
    local _petAddedTypeIndex = 0
    this.canAddedPetInfoList = BrokerManager.GetCanAddedPetList()
    if #(this.canAddedPetInfoList) > 0 then
        if BrokerManager.BrokerAddedPetId == 0 then
            for _, petInfo in pairs(this.canAddedPetInfoList) do
                if not petInfo.IsLocked then
                    BrokerManager.BrokerAddedPetId = petInfo.petId
                    break
                end
            end
            if BrokerManager.BrokerAddedPetId == 0 then
                local _count = #this.canAddedPetInfoList
                BrokerManager.BrokerAddedPetId = this.canAddedPetInfoList[_count].petId
            end
        end
        this.showMyAddedPetModel()
        _petAddedTypeIndex = 0
    else
        BrokerManager.BrokerAddedPetId = 0
        _petAddedTypeIndex = 1
    end
    this.Ctrl_PetAddedType:SetSelectedIndex(_petAddedTypeIndex)
    this.Input_SellPrice.text = ""
    this.Input_EvolutionPrice.text = ""
    this.Btn_SellSelected.selected = BrokerManager.IsSellSelected
    this.Btn_EvolutionSelected.selected = BrokerManager.IsEvolutionSelected
    this.clickIdex = 3
end
function this.onClickMyAddedChoosePet()
    if #PetManager.PetInfoList>0 then
        showUI(PanelNames.PetSelect,BrokerUtils.PETSHOP_PetType,this.canAddedPetInfoList)
    end
end
function this.onClickMyAddedConfirm()
    if not BrokerManager.canShopPet then
       return
    end
    if BrokerManager.CheckPetCanAdded(BrokerManager.BrokerAddedPetId) then
        UISysTips.AddMsg(getLanguage("PETSHOP_PetHaveConsignment") )
        return
    end
    local _sellPrice
    local _evolutionPrice
    if BrokerManager.IsSellSelected then
        _sellPrice = tonumber(this.Input_SellPrice.text)
        if nil == _sellPrice then
            UISysTips.AddMsg(getLanguage("PETSHOP_MyAddedSellNotNumberError"))
            return
        end
        if _sellPrice < BrokerManager.SellMinValue or _sellPrice > BrokerManager.SellMaxValue then
            UISysTips.AddMsg(string.format(getLanguage("PETSHOP_SellPrice"),BrokerManager.SellMinValue,BrokerManager.SellMaxValue))
            return
        end
    else
        _sellPrice = -1
    end
  
    if BrokerManager.IsEvolutionSelected then
        _evolutionPrice = tonumber(this.Input_EvolutionPrice.text)
        if nil == _evolutionPrice then
            UISysTips.AddMsg(getLanguage("PETSHOP_MyAddedEvolutionNotNumberError"))
            return
        else
            if _evolutionPrice < BrokerManager.EvolutionMinValue or _evolutionPrice > BrokerManager.EvolutionMaxValue then
                UISysTips.AddMsg(string.format(getLanguage("PETSHOP_EvolutionPrice"),BrokerManager.EvolutionMinValue,BrokerManager.EvolutionMaxValue))
                return
            end
        end
    else
        _evolutionPrice = -1
    end

    local _addedPetInfo = PetManager.GetPetInfoByPetId(BrokerManager.BrokerAddedPetId)
    if _addedPetInfo then
        if _addedPetInfo.IsLocked then
            UISysTips.AddMsg(getLanguage("PETSHOP_PetAddedLockError"))
            return
        elseif _evolutionPrice >= 0 then
            local _selectedIndex = PetManager.GetPetItemType(_addedPetInfo)
            if _selectedIndex == PetManager.PetItemType.MatingCD then
                UISysTips.AddMsg(getLanguage("PETSHOP_PetAddedWeaknessError"))
                return
            end
        end
    end
    if _sellPrice >= 0 or _evolutionPrice >= 0 then
        BrokerHandler.ReqBrokerGoodsRegister(BrokerManager.BrokerAddedPetId,_sellPrice,_evolutionPrice)
        if _addedPetInfo then
            PetManager.Track_putawayPet(_addedPetInfo.genes, _sellPrice, _evolutionPrice)
        end
    elseif not BrokerManager.IsSellSelected and (not BrokerManager.IsEvolutionSelected) then
        UISysTips.AddMsg(getLanguage("PETSHOP_PetSellOrEvolutionError"))
    else
        UISysTips.AddMsg(getLanguage("PETSHOP_PetAddedError"))
    end
end

function this.removMyAddedPetModel()
    if this.myAddedPetModelInfo then
        if this.myAddedPetModelInfo.modelGO then
            destroyImmediate(this.myAddedPetModelInfo.modelGO)
        end
        this.myAddedPetModelInfo.modelGO = nil
        this.myAddedPetModelInfo.parentGO = nil
        this.myAddedPetModelInfo.petId = nil
    end
end
function this.showMyAddedPetModel()
    local _myAddedPetInfo = PetManager.GetPetInfoByPetId(BrokerManager.BrokerAddedPetId)
    if _myAddedPetInfo and #_myAddedPetInfo.genes == PetManager.PetPart.Ornament then
        this.Model_MyAddedPet.visible = true
        this.Txt_MyAddedPetName.text = _myAddedPetInfo.petName
        if this.myAddedPetModelInfo.modelGO then
            this.myAddedPetModelInfo.petId = _myAddedPetInfo.petId;
            PetManager.PetModelRefresh(this.myAddedPetModelInfo, _myAddedPetInfo.genes, true)
        else
            this.removMyAddedPetModel()
            resMgr:LoadModelPrefab(PetManager.PetModelPrefab, function(go)
                this.myAddedPetModelInfo.modelGO = newObject(go)

                local _comp = this.myAddedPetModelInfo.modelGO:GetComponent("SkeletonGraphic")
                if _comp then
                    if this.myAddedPetModelInfo.modelGO then
                        _comp.material = resMgr.Pet_Copy_Mat
                        _comp.material:SetFloat("_StencilComp", 8)
                        _comp.material:SetFloat("_Stencil", 1);
                    end
                end
                
                this.myAddedPetModelInfo.parentGO = this.Model_MyAddedPet
                local _modelWrapper = this.myAddedPetModelInfo.modelWrapper
                this.myAddedPetModelInfo.modelWrapper = GoWrapper.New()
                this.myAddedPetModelInfo.petId = _myAddedPetInfo.petId
                PetManager.PetModelFirstSet(this.myAddedPetModelInfo, _myAddedPetInfo.genes, true, Vector3.New(0, 0, 0), Vector3.New(2.5, 2.5, 1))
                if _modelWrapper then
                    _modelWrapper:Dispose()
                end
            end)
        end

        local _go
        local _ctrlItem
        for k, v in pairs(_myAddedPetInfo.genes) do
            _go = this.Group_PetPartItem[k]
            _ctrlItem = CtrlManager.GetCtrl(PanelNames.PetPartItem)
            _ctrlItem.initData(_go, v);
        end
    else
        --没有宠物信息
        this.Txt_MyAddedPetName.text = getLanguage("PetMain_NoPet")
        this.Model_MyAddedPet.visible = false;
    end
end

function this.onClickSellSelected()
    BrokerManager.IsSellSelected = not BrokerManager.IsSellSelected
end
function this.onClickEvolutionSelected()
    BrokerManager.IsEvolutionSelected = not BrokerManager.IsEvolutionSelected
end

function this.eventSelectPet()
    this.clickIdex = 0
    this.onClickTabMyAdded()
end

function this.onClickRefresh()
    local isSend = nil
    if refreshTimeNum <= 0 then
        refreshTimeNum = 1
        isSend = true
        if timeRefresh == nil then
            timeRefresh = Timer.New(function()
                refreshTimeNum = 0;
            end, refreshTimeNum, 1);
        else
            timeRefresh:Reset(function()
                refreshTimeNum = 0;
            end, refreshTimeNum, 1);
        end
        timeRefresh:Start();
    else
        isSend = nil
    end
    return isSend
end
--------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------
--- 飞飞价格筛选 BEGIN
--------------------------------------------------------------------------------------------

--- 初始化飞飞价格筛选UI
--- @param root GObject 根节点
function this.initPriceFilterView(root)
    if root == nil then
        return
    end

    -- ui对象
    this.btnPriceClose  = root:GetChild("bgClose")
    this.btnPriceCancel = root:GetChild("btn_coupon1")
    this.btnPriceEnsure = root:GetChild("btn_coupon2")
    this.btnPriceRange1 = root:GetChild("btn_price1")
    this.btnPriceRange2 = root:GetChild("btn_price2")
    this.btnPriceRange3 = root:GetChild("btn_price3")
    this.btnPriceRange4 = root:GetChild("btn_price4")
    this.inputPriceMin  = root:GetChild("Input_SellPrice")
    this.inputPriceMax  = root:GetChild("Input_SellPrice2")
    this.ctrlPriceBtn   = root:GetController("btn_price")

    this.btnPriceClose.onClick:Add(this.onClosePriceFilterView)
    this.btnPriceCancel.onClick:Add(this.onBtnPriceCancel)
    this.btnPriceEnsure.onClick:Add(this.onBtnPriceEnsure)
    this.btnPriceRange1.onClick:Add(this.onClickBtnPriceRange1)
    this.btnPriceRange2.onClick:Add(this.onClickBtnPriceRange2)
    this.btnPriceRange3.onClick:Add(this.onClickBtnPriceRange3)
    this.btnPriceRange4.onClick:Add(this.onClickBtnPriceRange4)
    this.inputPriceMin.onChanged:Add(this.onInputPriceChanged)
    this.inputPriceMax.onChanged:Add(this.onInputPriceChanged)

    -- 同步配置数据
    mQuickPriceRange1_1 = HelperFunc.GetGlobalVlue(512)
    mQuickPriceRange1_2 = HelperFunc.GetGlobalVlue(513)
    mQuickPriceRange2   = HelperFunc.GetGlobalVlue(514)
    mQuickPriceRange3   = HelperFunc.GetGlobalVlue(515)
    mQuickPriceRange4_1 = HelperFunc.GetGlobalVlue(516)
    mQuickPriceRange4_2 = HelperFunc.GetGlobalVlue(517)

    -- 更新ui文字相关
    local txtTitle       = root:GetChild("name")
    local txtInputDesc   = root:GetChild("Desc")
    local txtRangeTo     = root:GetChild("Desc1")
    local txtQuickChoose = root:GetChild("Desc2")
    txtTitle.text        = getLanguage("PETSHOP_tips_001")
    txtInputDesc.text    = getLanguage("PETSHOP_tips_002")
    txtRangeTo.text      = getLanguage("PETSHOP_tips_003")
    txtQuickChoose.text  = getLanguage("PETSHOP_tips_004")
    this.btnPriceRange1.title = string.format(getLanguage("PETSHOP_tips_005"), mQuickPriceRange1_1[1], mQuickPriceRange1_1[2])
    this.btnPriceRange2.title = string.format(getLanguage("PETSHOP_tips_005"), mQuickPriceRange2[1],   mQuickPriceRange2[2])
    this.btnPriceRange3.title = string.format(getLanguage("PETSHOP_tips_005"), mQuickPriceRange3[1],   mQuickPriceRange3[2])
    this.btnPriceRange4.title = string.format(getLanguage("PETSHOP_tips_006"), mQuickPriceRange4_1[1])
end
function this.destroyPriceFilterView()
    mQuickPriceRange1_1 = nil
    mQuickPriceRange1_2 = nil
    mQuickPriceRange2   = nil
    mQuickPriceRange3   = nil
    mQuickPriceRange4_1 = nil
    mQuickPriceRange4_2 = nil
    this.btnPriceClose.onClick:Clear()
    this.btnPriceCancel.onClick:Clear()
    this.btnPriceEnsure.onClick:Clear()
    this.btnPriceRange1.onClick:Clear()
    this.btnPriceRange2.onClick:Clear()
    this.btnPriceRange3.onClick:Clear()
    this.btnPriceRange4.onClick:Clear()
    this.inputPriceMin.onChanged:Clear()
    this.inputPriceMax.onChanged:Clear()
end

--- 更新区间价格显示
--- @private
--- @param min number 最低价格
--- @param max number 最高价格
function this.refreshPriceInputText(min, max)
    this.inputPriceMin.text = tostring(min or "")
    this.inputPriceMax.text = tostring(max or "")
    if min == nil or max == nil then
        this.ctrlPriceBtn.selectedIndex = 0
    end
end

--- 更新按钮价格文本
--- @private
function this.refreshBtnPriceText()
    if BrokerManager.BrokerPetType == BrokerUtils.BrokerPetType.Buy then
        this.btnPriceRange1.title = string.format(getLanguage("PETSHOP_tips_005"), mQuickPriceRange1_1[1], mQuickPriceRange1_1[2])
        this.btnPriceRange4.title = string.format(getLanguage("PETSHOP_tips_006"), mQuickPriceRange4_1[1])
    elseif BrokerManager.BrokerPetType == BrokerUtils.BrokerPetType.Evolution then
        this.btnPriceRange1.title = string.format(getLanguage("PETSHOP_tips_005"), mQuickPriceRange1_2[1], mQuickPriceRange1_2[2])
        this.btnPriceRange4.title = string.format(getLanguage("PETSHOP_tips_006"), mQuickPriceRange4_2[1])
    end
end

--- 重置筛选状态
--- @private
function this.resetPriceFilter()
    mIsPriceFilter    = false
    mPriceSellMin     = nil
    mPriceSellMax     = nil
    mPriceEvolutioMin = nil
    mPriceEvolutioMax = nil
    this.refreshPriceFilterBtnState()
end

--- 快速选择价格区间
--- @private
--- @param min number 最低价格
--- @param max number 最高价格
function this.onChoosePriceRange(min, max)
    -- 设置区间值
    this.setPriceRange(min, max)

    -- 筛选开关
    mIsPriceFilter = this.checkIsPriceFilter()
    print('mIsPriceFilter: ', mIsPriceFilter)
    if mIsPriceFilter then
        this.refreshPriceRangeList()
        this.refreshPriceRangeTitle()
        this.refreshPriceFilterBtnState()
    elseif BrokerManager.BrokerPetType == BrokerUtils.BrokerPetType.Buy then
        this.onClickBrokerBuy()
    elseif BrokerManager.BrokerPetType == BrokerUtils.BrokerPetType.Evolution then
        this.onClickBrokerEvolution()
    end

    -- 关闭窗口
    this.onClosePriceFilterView()
end

--- 当前列表是否需要价格筛选
--- @private
--- @return boolean
function this.checkIsPriceFilter()
    if BrokerManager.BrokerPetType == BrokerUtils.BrokerPetType.Buy then
        if mPriceSellMin == BrokerManager.SellMinValue and mPriceSellMax == BrokerManager.SellMaxValue then
            return false
        end
        return true
    elseif BrokerManager.BrokerPetType == BrokerUtils.BrokerPetType.Evolution then
        if mPriceEvolutioMin == BrokerManager.EvolutionMinValue and mPriceEvolutioMax == BrokerManager.EvolutionMaxValue then
            return false
        end
        return true
    end
    return false
end

--- 检测价格输入文本是否合法
--- @param textStr string 文本字符串
--- @return boolean 是否合法
function this.checkInputValid(textStr)
    local bit = tonumber(string.sub(textStr, string.len(textStr) - 1))
    if (not bit) or type(bit) ~= "number" then
        UISysTips.AddMsg(getLanguage("PETSHOP_PriceNumber"))
        return false
    end
    return true
end

--- 设置价格筛选区间
--- @private
--- @param min number 最低价格
--- @param max number 最高价格
function this.setPriceRange(min, max)
    if BrokerManager.BrokerPetType == BrokerUtils.BrokerPetType.Buy then
        mPriceSellMin, mPriceSellMax = min, max
    elseif BrokerManager.BrokerPetType == BrokerUtils.BrokerPetType.Evolution then
        mPriceEvolutioMin, mPriceEvolutioMax = min, max
    end
end

--- 获取价格筛选区间值
--- @private
--- @param type number 列表类型
--- @return number 最低价格
--- @return number 最高价格
function this.getPriceRange(type)
    type = type or BrokerManager.BrokerPetType
    if type == BrokerUtils.BrokerPetType.Buy then
        return mPriceSellMin, mPriceSellMax
    end
    return mPriceEvolutioMin, mPriceEvolutioMax
end

--- 获取默认价格区间最小值
--- @private
--- @param type number 列表类型
--- @return number 最低价格
function this.getOriginPriceMin(type)
    type = type or BrokerManager.BrokerPetType
    if type == BrokerUtils.BrokerPetType.Buy then
        return BrokerManager.SellMinValue
    end
    return BrokerManager.EvolutionMinValue
end

--- 获取默认价格区间最大值
--- @private
--- @param type number 列表类型
--- @return number 最高价格
function this.getOriginPriceMax(type)
    type = type or BrokerManager.BrokerPetType
    if type == BrokerUtils.BrokerPetType.Buy then
        return BrokerManager.SellMaxValue
    end
    return BrokerManager.EvolutionMaxValue
end

--- 选择预选价格区间1 [10, 99]
--- @private
function this.onClickBtnPriceRange1()
    if BrokerManager.BrokerPetType == BrokerUtils.BrokerPetType.Buy then
        this.refreshPriceInputText(mQuickPriceRange1_1[1], mQuickPriceRange1_1[2])
    elseif BrokerManager.BrokerPetType == BrokerUtils.BrokerPetType.Evolution then
        this.refreshPriceInputText(mQuickPriceRange1_2[1], mQuickPriceRange1_2[2])
    end
end
--- 选择预选价格区间2 [100, 499]
--- @private
function this.onClickBtnPriceRange2()
    this.refreshPriceInputText(mQuickPriceRange2[1], mQuickPriceRange2[2])
end
--- 选择预选价格区间3 [500, 999]
--- @private
function this.onClickBtnPriceRange3()
    this.refreshPriceInputText(mQuickPriceRange3[1], mQuickPriceRange3[2])
end
--- 选择预选价格区间4 [1000, +]
--- @private
function this.onClickBtnPriceRange4()
    if BrokerManager.BrokerPetType == BrokerUtils.BrokerPetType.Buy then
        this.refreshPriceInputText(mQuickPriceRange4_1[1], mQuickPriceRange4_1[2])
    elseif BrokerManager.BrokerPetType == BrokerUtils.BrokerPetType.Evolution then
        this.refreshPriceInputText(mQuickPriceRange4_2[1], mQuickPriceRange4_2[2])
    end
end

--- 确定选择筛选价格
--- @private
function this.onBtnPriceEnsure()
    local minstr, maxstr = this.inputPriceMin.text, this.inputPriceMax.text
    if minstr == "" or maxstr == "" then
        this.onClosePriceFilterView()
        return
    end

    -- 非法字符串
    if not this.checkInputValid(minstr) or not this.checkInputValid(maxstr) then
        return
    end

    -- 价格不合理
    local min, max = tonumber(minstr), tonumber(maxstr)
    local originMin = this.getOriginPriceMin()
    if min < originMin or max < originMin or min > max then
        UISysTips.AddMsg(getLanguage("PETSHOP_tips_009"))
        return
    end

    this.onChoosePriceRange(min, max)
end
--- 取消选择筛选价格
--- @private
function this.onBtnPriceCancel()
    this.onClosePriceFilterView()
end

--- 输入文本框内容变更
--- @param evt any
--- @private
function this.onInputPriceChanged(evt)
    if not evt or not evt.sender then
        return
    end
    if not this.checkInputValid(evt.sender.text) then
        return
    end
    this.ctrlPriceBtn.selectedIndex = 0
end

-- 关闭价格筛选界面
function this.onClosePriceFilterView()
    this.ctrlPriceFilter.selectedIndex = 0
end
-----------------------------------------------------------------------------------------------
--- 飞飞价格筛选 END
--------------------------------------------------------------------------------------------

return UIPetShop